package edu.fim.aspect;

import javax.persistence.EntityTransaction;

import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

@Aspect
public class TransactionManager {

	private EntityTransaction transaction;
	
	public TransactionManager() {
	}
	
	public void setTransaction(EntityTransaction transaction) {
		this.transaction = transaction;
	}

	@Pointcut("@annotation(Transactional)")
	public void transactionalMethods() {
	}

	@Before("transactionalMethods()")
	public void beginTransaction() {
		transaction.begin();
	}

	@After("transactionalMethods()")
	public void commitTransaction() {
		transaction.commit();
	}
}